package com.baidu.health.service;

import com.baidu.health.mapper.TbArticleMapper;
import com.baidu.health.pojo.TbArticle;
import com.baidu.health.pojo.resultVo.articleVo;
import com.baidu.health.pojo.resultVo.resultVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baidu.health.pojo.TbLike;
import com.baidu.health.mapper.TbLikeMapper;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 *
 */
@Service
public class TbLikeServiceImpl extends ServiceImpl<TbLikeMapper, TbLike>{

    @Autowired
    TbLikeMapper likeMapper;

    @Autowired
    TbArticleMapper articleMapper;

    @Autowired
    RabbitTemplate rabbitTemplate;

    public resultVo likeArticle(TbLike like) {

        rabbitTemplate.convertAndSend("likeExchanges","like",like);
        return new resultVo(200,"正在处理",null);

    }

    public articleVo getLikeList(Integer pageNum, Integer pageSize) {
        QueryWrapper<TbLike> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(TbLike::getDelFlag,0);
        int size = likeMapper.selectList(wrapper).size();
        Page<TbLike> page = new Page<>(pageNum,pageSize);
        Page<TbLike> likePage = likeMapper.selectPage(page, wrapper);
        return new articleVo(true,200,"查询成功",likePage,size);
    }
}




